﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="tab_share.aspx.cs" Inherits="tab_share"
   Theme="default" EnableViewState="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
   <title>Nexus - Share my Tabs</title>
   <style>
      .header_share
      {
         background-color: #abcdef;
         border: solid 1px black;
         padding: 3px;
      }
      .inputs_share
      {
         border: solid 1px black;
         padding: 3px;
      }
   </style>
</head>
<body>
   <form id="frm" runat="server">
   <asp:ScriptManager ID="ScriptManager" runat="server" />
   <table border="0">
      <tr valign="top">
         <td class="header_share">
            <b>I want to share </b>
            <asp:Literal ID="lbl_Tab" runat="server" />
            Tab
         </td>
      </tr>
      <tr valign="top">
         <td>
            <asp:UpdatePanel ID="UP" runat="server" UpdateMode="Conditional">
               <ContentTemplate>
                  <asp:Panel ID="Panel_ShareWithWho" runat="server" GroupingText="Step 1 - With these people..">
                     <br />
                     Please enter each email address (e.g someone@gmail.com)
                     <br />(Each valid NUSNET ID can only be added once, irrespective of the external email used.)
                     <br />
                     or
                     <br />
                     NUSNET UserID (e.g NUSSTU\u0812345) as a new line.
                     <br />
                     <asp:Literal ID="lbl_Error" runat="server" Text="<font color=red>We have found some error validating the users, please check the users marked with *</font>" Visible="false" />
                     <asp:TextBox ID="txt_ShareWith" runat="server" TextMode="MultiLine" Rows="10" 
                        Width="100%" ></asp:TextBox>
                     <asp:Button ID="btn_Next1" runat="server" Text="Next >"
                        OnClick="btn_Next1_Click" />
                  </asp:Panel>
                  <asp:Panel ID="Panel_SetAccessRights" runat="server" GroupingText="Step 2 - Set access rights..">
                  <asp:CheckBox ID="cb_AdvancedRights" runat="server" Text="Show Full Permission Grid" onclick="ShowAdvancedRights(this)" />
                     <asp:GridView ID="GV_AccessRights" runat="server" AutoGenerateColumns="False" DataKeyNames="Email">
                        <Columns>
                           <asp:BoundField DataField="DisplayName" HeaderText="User" HtmlEncode="false"  />
                           <asp:TemplateField HeaderText="Permission">
                              <ItemTemplate>
                                 <asp:DropDownList ID="ddl" runat="server" onchange="DDLChange(this)">
                                 <asp:ListItem Value="0">Read</asp:ListItem>
                                 <asp:ListItem Value="1">Read/Write</asp:ListItem>
                                 <asp:ListItem Value="2">All Rights</asp:ListItem>
                                 </asp:DropDownList> 
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>                            
                           <asp:TemplateField HeaderText="Read">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Read" runat="server" Checked='<%# Bind("Tab_Read") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />                              
                           </asp:TemplateField>                            
                           <asp:TemplateField HeaderText="Edit Name">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Tab_EditName" runat="server" Checked='<%# Bind("Tab_EditName") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Share">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Tab_Share" runat="server" Checked='<%# Bind("Tab_Share") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Delete">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Tab_Delete" runat="server" Checked='<%# Bind("Tab_Delete") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Add Widget">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Tab_AddWidgets" runat="server" Checked='<%# Bind("Tab_AddWidgets") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Change Layout">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Tab_ChangeLayout" runat="server" Checked='<%# Bind("Tab_ChangeLayout") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Change Theme">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Tab_ChangeTheme" runat="server" Checked='<%# Bind("Tab_ChangeTheme") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Edit Widget Properties">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Widget_Edit" runat="server" Checked='<%# Bind("Widget_Edit") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Reorder Widget">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Widget_Reorder" runat="server" Checked='<%# Bind("Widget_Reorder") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Delete Widget">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Widget_Delete" runat="server" Checked='<%# Bind("Widget_Delete") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>
                           <asp:TemplateField HeaderText="Edit Widget Title">
                              <ItemTemplate>
                                 <asp:CheckBox ID="cb_Widget_EditTitle" runat="server" Checked='<%# Bind("Widget_EditTitle") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />
                           </asp:TemplateField>                          
                        </Columns>
                     </asp:GridView>
                     <asp:Button ID="btn_Back" runat="server" Text="< Back" 
                        onclick="btn_Back1_Click" />
                     <asp:Button ID="btn_Confirm" runat="server" Text="Next >" 
                        onclick="btn_Confirm_Click" />
                  </asp:Panel>
                  <asp:Panel ID="Panel_Confirm" runat="server" GroupingText="Final Step - Confirm Users & Send Email" Visible="false">
                     <asp:GridView ID="GV_Users" runat="server" AutoGenerateColumns="False" DataKeyNames="Email"
                        onrowdatabound="GV_Users_RowDataBound">
                        <Columns>
                           <asp:TemplateField HeaderText="Name">
                              <ItemTemplate>
                                 <asp:TextBox ID="txt_Name" runat="server" Text='<%# Bind("UserName") %>' />
                              </ItemTemplate>
                              <ItemStyle VerticalAlign="Middle" />                              
                           </asp:TemplateField>                            
                           <asp:BoundField DataField="Email" HeaderText="Email" />                           
                        </Columns>
                     </asp:GridView>
                     <br />
                     <b>The following email will be sent to let these users know they've been added.</b>
                     <table border="0" width="100%">
                     <tr><td width="5%">From</td><td width="*"><asp:Literal ID="lbl_From" runat="server" /></td></tr>
                     <tr><td>Subject</td><td><asp:TextBox Width="100%" ID="txt_Subject" runat="server" /></td></tr>
                     <tr valign="top"><td>Body</td><td>
                        <asp:TextBox Width="100%" rows="10" ID="txt_Body" Text="" runat="server" TextMode="MultiLine" />
                        <AjaxCTK:TextBoxWatermarkExtender ID="txt_Body_TextBoxWatermarkExtender" 
                           runat="server" Enabled="True" TargetControlID="txt_Body" 
                           WatermarkText="Add your personalized message here">
                        </AjaxCTK:TextBoxWatermarkExtender>
                        <br /><asp:Literal ID="lbl_Body" runat="server" />
                     </td></tr>
                     </table>
                     <asp:Button ID="btn_Back2" runat="server" Text="< Back" 
                        onclick="btn_Back2_Click" />
                     <asp:Button ID="btn_Finish" runat="server" Text="Finish" 
                        onclick="btn_Finish_Click" />                  
                  </asp:Panel>
                  <asp:Panel ID="Panel_Complete" runat="server" GroupingText="Share Tab Sequence Completed" Visible="false">
                  You have successfully shared this tab!
                  <asp:Literal ID="lbl_Results" runat="server" />
                  <br />Click <a href="javascript:void(0)" onclick="self.close()">here</a> to close this window.</asp:Panel>
               </ContentTemplate>
            </asp:UpdatePanel>
         </td>
   </form>
   <script language="javascript">
//Write history
function WriteHistory(message)
{
	var historyDiv = document.getElementById('pageHistory');
	if(historyDiv){
	   while(historyDiv.childNodes.length > 500)
	   {
	      historyDiv.removeChild(historyDiv.lastChild);	      
	   }
		historyDiv.insertBefore(document.createElement('BR'), historyDiv.firstChild);
		historyDiv.insertBefore(document.createTextNode(message), historyDiv.firstChild);
	}
}   

//Gets the Window Width and Height
function getWindowWidthHeight()
{
   var result = {};
   result["Width"] = f_clientWidth();
   result["Height"] = f_clientHeight();
   
   return result;
}

//Gets the Window Width
function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

//Gets the Window Height
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

//Filter function
function f_filterResults(n_win, n_docel, n_body) {
/*
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
*/
   if (!n_win)
      n_win = 0;
      
   if (!n_docel)
      n_docel = 0;
      
   if (!n_body)
      n_body = 0;
      
   return Math.max(n_body, Math.max(n_docel, n_win));
}

      function ShowAdvancedRights(cb)
      {
         var GridView = $get('<%= GV_AccessRights.ClientID %>');
         var TableRows =GridView.getElementsByTagName("TR");
         var DisplaySimple = "";
         var DisplayAdvance = "";
         var Width = 450;
         var Height = 400;
         
         var CurDimension = getWindowWidthHeight();
         
         if (cb.checked)
         {
            DisplaySimple = "none";
            DisplayAdvance = "";
         }
         else
         {
            DisplaySimple = "";
            DisplayAdvance = "none";
         }

         //tr starts with an empty cell, then first column is userid, so start with 2nd column
         for(var i=0;i<TableRows.length;i++)
         {
            var j = 0;
            var isFirst = true;
            for(;j<TableRows[i].childNodes.length;j++)
            {
               if (TableRows[i].childNodes[j].style)
               {
                  if (isFirst)
                  {
                     isFirst = false;
                  }
                  else
                  {                   
                     TableRows[i].childNodes[j].style.display = DisplaySimple;
                     j++;
                     break;
                  }
               }
            }
            
            for(;j<TableRows[i].childNodes.length;j++)
            {
               if (TableRows[i].childNodes[j].style)
                  TableRows[i].childNodes[j].style.display = DisplayAdvance;
            }
         }
      }
      
      function DDLChange(ddl)
      {
      //0 - read, 1-readwrite, 2-full
         var id = ddl.id.replace("ddl", "");
         $get(id + "cb_Read").checked = ddl.value == "0" || ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Tab_EditName").checked = ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Tab_Share").checked = ddl.value == "2";
         $get(id + "cb_Tab_Delete").checked = ddl.value == "2";
         $get(id + "cb_Tab_AddWidgets").checked = ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Tab_ChangeLayout").checked = ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Tab_ChangeTheme").checked = ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Widget_Edit").checked = ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Widget_Reorder").checked = ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Widget_Delete").checked = ddl.value == "1" || ddl.value == "2";
         $get(id + "cb_Widget_EditTitle").checked = ddl.value == "1" || ddl.value == "2";
      }      
   </script>
   <span id='pageHistory'></span>
   <!--
   <textarea name="txt" id="txt"></textarea>
   <input type="button" value="xxx" onclick="eval($get('txt').value)" />
   -->
</body>
</html>
